<div th:fragment="detailfooter" xmlns:th="http://www.thymeleaf.org">
    <footer class="footer bg-white">

        <div class="footer-meta">
            <div class="footer-container">
                <div class="meta-item meta-copyright">
                    <div class="meta-copyright-info">
                        <a th:href="@{/}" class="info-logo">
                            <img th:src="@{/ui/pages/img/logo.png}"  />
                        </a>
                        <div class="info-text">
                            <p>一生有所追求.</p>
                            <p>Powered by <a href="https://github.com/otale/tale" target="_blank" rel="nofollow">Tale</a>
                            </p>
                            <p>&copy; 2017 <a href="http://git.oschina.net/oneper/base/tree/dev/">hongb</a></p>
                        </div>
                    </div>
                </div>

                <div class="meta-item meta-posts">
                    <h3 class="meta-title">最新文章</h3>
                    <div id="recentdiv">

                    </div>


                </div>

                <div class="meta-item meta-comments">
                    <h3 class="meta-title">人生格言</h3>
                    <li>
                        <a href="#">大多数的人一辈子只做了三件事：自欺、欺人、被人欺。</a>
                    </li>
                    <li>
                        <a href="#">心是最大的骗子，别人能骗你一时，而它却会骗你一辈子。</a>
                    </li>
                    <li>
                        <a href="#">放弃时间的人，时间也会放弃他。</a>
                    </li>
                    <li>
                        <a href="#">你希望掌握永恒，那你必须控制现在。</a>
                    </li>
                </div>
            </div>
        </div>
    </footer>

    <div id="directory-content" class="directory-content">
        <div id="directory"></div>
    </div>
    <script th:inline="javascript">
        /*<![CDATA[*/


        var basepath = /*[[${#httpServletRequest.getContextPath()}]]*/ "/";

        $(function () {
            $.get(basepath+'/pages/re_articles',function (data) {
                var re_articles = data.data.data;

                console.info(re_articles);
                $.each(re_articles,function (i,v) {
                    console.info(v.id);
                    var li = "<li><a href='"+basepath+"/pages/article/"+v.id+"'>"+v.title+"</a></li>";
                    $("#recentdiv").append(li);
                });

            });
        });
        $('#directory').html('');
        var postDirectoryBuild = function() {
            var postChildren = function children(childNodes, reg) {
                    var result = [],
                        isReg = typeof reg === 'object',
                        isStr = typeof reg === 'string',
                        node, i, len;
                    for (i = 0, len = childNodes.length; i < len; i++) {
                        node = childNodes[i];
                        if ((node.nodeType === 1 || node.nodeType === 9) &&
                            (!reg ||
                            isReg && reg.test(node.tagName.toLowerCase()) ||
                            isStr && node.tagName.toLowerCase() === reg)) {
                            result.push(node);
                        }
                    }
                    return result;
                },
                createPostDirectory = function(article, directory, isDirNum) {
                    var contentArr = [],
                        titleId = [],
                        levelArr, root, level,
                        currentList, list, li, link, i, len;
                    levelArr = (function(article, contentArr, titleId) {
                        var titleElem = postChildren(article.childNodes, /^h\d$/),
                            levelArr = [],
                            lastNum = 1,
                            lastRevNum = 1,
                            count = 0,
                            guid = 1,
                            id = 'directory' + (Math.random() + '').replace(/\D/, ''),
                            lastRevNum, num, elem;
                        while (titleElem.length) {
                            elem = titleElem.shift();
                            contentArr.push(elem.innerHTML);
                            num = +elem.tagName.match(/\d/)[0];
                            if (num > lastNum) {
                                levelArr.push(1);
                                lastRevNum += 1;
                            } else if (num === lastRevNum ||
                                num > lastRevNum && num <= lastNum) {
                                levelArr.push(0);
                                lastRevNum = lastRevNum;
                            } else if (num < lastRevNum) {
                                levelArr.push(num - lastRevNum);
                                lastRevNum = num;
                            }
                            count += levelArr[levelArr.length - 1];
                            lastNum = num;
                            elem.id = elem.id || (id + guid++);
                            titleId.push(elem.id);
                        }
                        if (count !== 0 && levelArr[0] === 1) levelArr[0] = 0;

                        return levelArr;
                    })(article, contentArr, titleId);
                    currentList = root = document.createElement('ul');
                    dirNum = [0];
                    for (i = 0, len = levelArr.length; i < len; i++) {
                        level = levelArr[i];
                        if (level === 1) {
                            list = document.createElement('ul');
                            if (!currentList.lastElementChild) {
                                currentList.appendChild(document.createElement('li'));
                            }
                            currentList.lastElementChild.appendChild(list);
                            currentList = list;
                            dirNum.push(0);
                        } else if (level < 0) {
                            level *= 2;
                            while (level++) {
                                if (level % 2) dirNum.pop();
                                currentList = currentList.parentNode;
                            }
                        }
                        dirNum[dirNum.length - 1]++;
                        li = document.createElement('li');
                        link = document.createElement('a');
                        link.href = '#' + titleId[i];
                        link.innerHTML = !isDirNum ? contentArr[i] :
                            dirNum.join('.') + ' ' + contentArr[i] ;
                        li.appendChild(link);
                        currentList.appendChild(li);
                    }
                    directory.appendChild(root);
                };
            createPostDirectory(document.getElementById('post-content'),document.getElementById('directory'), true);
        };
        postDirectoryBuild();
        /*]]>*/
    </script>

    <script src="//cdn.bootcss.com/headroom/0.9.1/headroom.min.js"></script>
    <script src="//cdn.bootcss.com/highlight.js/9.9.0/highlight.min.js"></script>
    <script src="//cdn.bootcss.com/instantclick/3.0.1/instantclick.min.js"></script>
    <script type="text/javascript">
        /*<![CDATA[*/
        var postDirectory = new Headroom(document.getElementById("directory-content"), {
            tolerance: 0,
            offset : 100,
            classes: {
                initial: "initial",
                pinned: "pinned",
                unpinned: "unpinned"
            }
        });
        var header = new Headroom(document.getElementById("header"), {
            tolerance: 10,
            offset : 80,
            classes: {
                initial: "animated",
                pinned: "slideDown",
                unpinned: "slideUp"
            }
        });
        header.init();
        $('#search-inp').keypress(function (e) {
            var key = e.which; //e.which是按键的值
            if (key == 13) {
                var q = $(this).val();
                if (q && q != '') {
                    window.location.href = basepath+'/pages/search/' + q;
                }
            }
        });

        InstantClick.on('change', function (isInitialLoad) {
            var blocks = document.querySelectorAll('pre code');
            for (var i = 0; i < blocks.length; i++) {
                hljs.highlightBlock(blocks[i]);
            }
            if (isInitialLoad === false) {
                if (typeof ga !== 'undefined') ga('send', 'pageview', location.pathname + location.search);
            }
        });
        InstantClick.init();
        /*]]>*/
    </script>
</div>